package middleware

import (
	"fmt"
	"go.zero.learn/internal/manage"
	"net/http"
)

func ExceptionMiddleware(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		defer func() {
			if err := recover(); err != nil {
				fmt.Println("=========这是全局处理异常==========")
				fmt.Println(err)
				fmt.Println("=========这是全局处理异常==========")
				manage.ResponseHandler(w, nil, &manage.ServerError)
			}
		}()
		next(w, r)
	}
}
